package com.kanshu.ksgb.fastread.doudou.module.book.adapter;

import android.content.Context;
import android.text.TextUtils;

import com.dl7.recycler.adapter.BaseQuickAdapter;
import com.dl7.recycler.adapter.BaseViewHolder;
import com.kanshu.ksgb.fastread.doudou.R;
import com.kanshu.ksgb.fastread.doudou.app.constants.ARouterConfig;
import com.kanshu.ksgb.fastread.doudou.common.business.ad.presenter.AdPresenter;
import com.kanshu.ksgb.fastread.doudou.common.business.manager.MMKVUserManager;
import com.kanshu.ksgb.fastread.doudou.common.imageloader.GlideImageLoader;
import com.kanshu.ksgb.fastread.doudou.common.urlrouter.UrlRouter;
import com.kanshu.ksgb.fastread.doudou.common.util.ARouterUtils;
import com.kanshu.ksgb.fastread.doudou.module.book.bean.ShelfGoodPresent;

import java.util.List;

/**
 * 好书推荐适配器
 * Created by wcy on 2017\6\19 0019.
 */
public class BookShelfGoodPresentAdapter extends BaseQuickAdapter<ShelfGoodPresent> {

    public BookShelfGoodPresentAdapter(Context context, List<ShelfGoodPresent> data) {
        super(context, data);
    }

    @Override
    protected int attachLayoutRes() {
        return R.layout.item_shelf_good_present_layout307;
    }

    @Override
    protected void convert(BaseViewHolder holder, final ShelfGoodPresent item, final int position) {
        holder.setText(R.id.title, item.title);
        GlideImageLoader.load(item.img_url, holder.getView(R.id.cover));
        holder.getConvertView().setOnClickListener(v -> {
            //检查是否为分红池页面
            if(!TextUtils.isEmpty(item.jump_url) && item.jump_url.contains("sign_in_profit")){
                //检查是否登陆
                int loginState = MMKVUserManager.getInstance().getLoginState();
                if (loginState != 200) {
                    ARouterUtils.toActivity(ARouterConfig.PERSONAL_LOGIN_IN, "phone", "");
                } else {
                    ARouterUtils.toActivity(ARouterConfig.PERSONAL_PROFIT);
                }
            }else{
                //正常跳转
                UrlRouter.from(mContext).jump(item.jump_url);
            }

            if (!TextUtils.isEmpty(item.jump_url)) {
                if (item.jump_url.contains("new_gifts")) {
                    AdPresenter.Companion.pvuvStatics(R.string.XJHONGBAO);
                } else if (item.jump_url.contains("sub_tab_index")) {
                    String s = item.jump_url.substring(item.jump_url.length() - 1);
                    if (!TextUtils.isEmpty(s) && TextUtils.isDigitsOnly(s)) {
                        int sub = Integer.parseInt(s);
                        if (sub == 2) {
                            AdPresenter.Companion.pvuvStatics(R.string.DQFAQIAN);
                        } else if (sub == 1){
                            AdPresenter.Companion.pvuvStatics(R.string.XJJIANGLI);
                        } else if (sub == 0) {
                            AdPresenter.Companion.pvuvStatics(R.string.LJTIXIAN);
                        }
                    }
                } else if (item.jump_url.contains("sign_in_profit")) {
                    AdPresenter.Companion.pvuvStatics(R.string.HBHUODONG);
                }
            }
        });
    }

}
